class midiOutMod extends Mod
{
  MidiOutput midiOutput;
  midiOutMod(Mod tempParent, float tempBx, float tempBy, int tempIndex) {
    super(tempParent, tempBx, tempBy, tempIndex);
    //myBus = new MidiBus(, "LoopBe Internal MIDI", "LoopBe Internal MIDI"
    img="mid";
    loadImg(img);
    name="midi";
    minWx=50;
    minWy=90;
    iPs[ip]=new inPort(this, 2, "key");
    iPs[ip]=new inPort(this, 2, "vel");
    iPs[ip]=new inPort(this, 2, "on/off");
    iPs[ip]=new inPort(this, 2, "channel");
    updatePorts();
    MidiOutputDevice devices[] = RWMidi.getOutputDevices();
    for (int i = 0; i < devices.length; i++) {
      println(i + ": " + devices[i].getName());
    }
    // Currently we assume the first device (#0) is the one we want
    midiOutput = RWMidi.getOutputDevices()[2].createOutput();
  }
  void go() {
    if (iPs[2].floatV==1) {
      println("noteon");
      //myBus.sendNoteOn(iPs[3].floatV, iPs[0].floatV, iPs[1].floatV);
      println(iPs[3].floatV+" "+ iPs[0].floatV+" "+ iPs[1].floatV);
      midiOutput.sendNoteOn((int)iPs[3].floatV, (int)iPs[0].floatV, (int)iPs[1].floatV);
    }
    if (iPs[2].floatV==0) {
      //myBus.sendNoteOff(iPs[3].floatV, iPs[0].floatV, iPs[1].floatV);
      midiOutput.sendNoteOff((int)iPs[3].floatV, (int)iPs[0].floatV, (int)iPs[1].floatV);
    }
  }
}

class midiInMod extends Mod
{

  MidiInput midiInput;

  midiInMod(Mod tempParent, float tempBx, float tempBy, int tempIndex) {
    super(tempParent, tempBx, tempBy, tempIndex);
    img="mid";
    loadImg(img);
    name="midi";
    minWx=50;
    minWy=90;
    oPs[op]=new outPort(this, 2, "key");
    oPs[op]=new outPort(this, 2, "vel");
    oPs[op]=new outPort(this, 2, "on/off");
    oPs[op]=new outPort(this, 2, "channel");
    updatePorts();
    isInput=true;
    MidiInputDevice devices[] = RWMidi.getInputDevices();
    for (int i = 0; i < devices.length; i++) {
      println(i + ": (in) " + devices[i].getName());
    }
    // Currently we assume the first device (#0) is the one we want
    midiInput = RWMidi.getInputDevices()[0].createInput(this);
  }
  void go() {
    /* if(iPs[2].floatV==1){
     println("noteon");););););
     //myBus.sendNoteOn(iPs[3].floatV, iPs[0].floatV, iPs[1].floatV);
     println(iPs[3].floatV+" "+ iPs[0].floatV+" "+ iPs[1].floatV);
     midiOutput.sendNoteOn(iPs[3].floatV, iPs[0].floatV, iPs[1].floatV);
     }
     if(iPs[2].floatV==0){
     //myBus.sendNoteOff(iPs[3].floatV, iPs[0].floatV, iPs[1].floatV);
     midiOutput.sendNoteOff(iPs[3].floatV, iPs[0].floatV, iPs[1].floatV);
     }*/
    doStack();
  }

  void noteOnReceived(Note note) {
    println("note on " + note.getPitch());
  }
}

